<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>桌面插件管理</title>
	<%@include file="/WEB-INF/views/include/head.jsp" %>
	<script type="text/javascript">
		$(document).ready(function() {
			initGrid();		 
		});

	    function initGrid(){
	    	$("#jqGrid").jqGrid({
                url: '${ctxAdmin}/sys/desktopPlug/loadData',
                mtype: "POST",
                datatype: "json",
                responsive:true,
                page: 1,
                colModel: [
                            	                                       
					{ label: 'id', name: 'id', key: true, hidden:true}, 
                    { label: '插件名称',name: 'name',index: 'name',width: 120},
/*                     { label: '尺寸(宽*高)',name: 'widthHeight',width: 120}, */
                    { label: '预览', name: 'icon',index: 'icon',width: 180}, 
                    { label: 'url', name: 'url',index: 'url',width:260},
                    { label: '备注', name: 'remark',index:'remark',width: 280},                                 
                    {label:'操作',name:'cz',search:false,sortable:false,title:false,formatter:czFmt,width:120}
                ],
				viewrecords: true,
                height: height,
                rowNum: 10,
                rowList:[100],
                loadonce:false,
                multiselect: true,
                autowidth: true,
                pager: "#jqGridPager"
            });
			$('#jqGrid').jqGrid('navGrid','#jqGridPager',{edit:false,add:false,del:false,search:false});
	    }
	 
	    function czFmt(c,o,r){
			var res='';
			var id=r.id;
			res+='<shiro:hasPermission name="sys:desktopPlug:edit">';
			res+='<a class="btn-success btn-sm" href="${ctxAdmin}/sys/desktopPlug/form?id='+id+'">修改</a>&nbsp;&nbsp;';
			res+='<a class="btn-danger btn-sm" href="javascript:void(0)" onclick="deleteData(\''+id+'\')">删除</a>&nbsp;&nbsp;';
			res+='</shiro:hasPermission>';
			return res;
		}

		function deleteData(id){		
			confirmx('你确定要删除此数据吗？',null,function(){
					$.ajax({
					url:'${ctxAdmin}/sys/desktopPlug/delete',
					type:'post',
					dataType:'json',
					data:{id:id},
					success:function(res){
					var code = res.code;
					var message = res.message;				
					layer.msg(message);
					$('#jqGrid').trigger("reloadGrid");
					}
				});}		
			);
			
		}
			
		function deleteDataBatch(ids){		
		var _ids=$('#jqGrid').jqGrid('getGridParam','selarrrow');
		if(_ids.length==0){
		layer.msg("请选择要操作的行！");
		return
		}
		var ids = _ids.join(",");	
		confirmx('要删除选中的项吗？',null,function(){			
				$.ajax({
					url:'${ctxAdmin}/sys/desktopPlug/delete',
					type:'post',
					dataType:'json',
					data:{id:ids},
					success:function(res){
					var code = res.code;
					var message = res.message;				
					layer.msg(message);
					$('#jqGrid').trigger("reloadGrid");
					}
				});				
				}		
			);		
		}
		
		$(function() {
			$('#btnSubmit').click(function() {
				var name = $("#name").val();						
				$('#jqGrid').jqGrid('setGridParam', {
					datatype : 'json',
					postData : {
						'name' : name
					}
				}).trigger("reloadGrid");
			});
			
		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctxAdmin}/sys/desktopPlug/">桌面插件列表</a></li>
		<shiro:hasPermission name="sys:desktopPlug:edit"><li><a href="${ctxAdmin}/sys/desktopPlug/form">桌面插件添加</a></li></shiro:hasPermission>
	</ul>


	<div class="jqGrid_wrapper">
	
		<div class="search_row">
				
			<label class="col-sm-1">插件名称：</label>
			<div class="col-sm-2">
			<input id="name" name="name" type="text" class="form-control ipt-search" />
			</div>

										
			<div class="col-sm-search" style="width: 26%">
			&nbsp;&nbsp;&nbsp;<input id="btnSubmit" class="btn btn-sm btn-success" type="button"  value="查询" />
			&nbsp;&nbsp; <input id="btnReset" class="btn btn-sm btn-danger" type="button" value="重 置" />
			<shiro:hasPermission name="sys:desktopPlug:edit">
			&nbsp;&nbsp; <input id="btnDelete" class="btn btn-sm btn-danger" type="button" onclick="deleteDataBatch()" value="批量删除" />
			</shiro:hasPermission>
			
			</div>			
		</div>
		<div class="search_row_split"></div>
		<table id="jqGrid"></table>
		<div id="jqGridPager"></div>
	</div>
	
</body>
</html>